package com.kaishengit.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kaishengit.pojo.Idea;
import com.kaishengit.pojo.Ideacomment;
import com.kaishengit.pojo.User;
import com.kaishengit.util.CreateTime;
import com.kaishengit.util.MyUUID;
import com.kaishengit.util.Outtime;

@Service
@Transactional
public class IdeacommService extends BaseService {

	public Ideacomment findById(String id) {

		return getIdeacommDao().findById(id);
	}

	public List<Ideacomment> getComm(Idea idea) {
 
		List<Ideacomment> ideacomment = getIdeacommDao().findByIdea(idea);
		for (int i = 0; i < ideacomment.size(); i++) {
			ideacomment.get(i).setOuttime(
					Outtime.OutDateTime(ideacomment.get(i).getCreatetime()));
		}
		return ideacomment;
	}

	public void save(Ideacomment ideacomment, Idea idea, User user) {

		ideacomment.setId(MyUUID.createUUID().toString());
		ideacomment.setCreatetime(CreateTime.createTime());
		ideacomment.setIdea(idea);
		ideacomment.setUser(user);

		getIdeacommDao().save(ideacomment);

	}

	public void del(String id) {

		getIdeacommDao().del(id);

	}

	public void dels(Idea idea) {

		for (Ideacomment ideacomment : getComm(idea)) {
			getIdeacommDao().del(ideacomment);
		}

		getIdeaDao().del(idea);

	}
}
